use BGT_2007_2010_2012_withvars_021716_mechanisms.dta, clear

clear
set more off

global exper need4
global educ needbd_plus

global dto "change_openings_per_emp"
global initial "initialneed"
global level2000 "avgageexp"
*global covars    "initialneed change_openings_per_emp avgageexp"
global covars    "initialneed avgageexp"
global stdcovars "stdinitialneed stdavgageexp stdchange_openings_per_emp"

global occfe "i.occsoc_num"
global stfe "i.statefip"
global timefe "b2012.year"

global styearfe "i.styear"
global occyearfe "i.occyear"

global restric "if minto>15 "

global flow "\parbox[c]{1.8cm}{\centering "
global lte "$\leq$"
global gte "$\geq$"

global weight "[w=occshare_state]"

use "BGT_2007_2010_2012_firmjobtitle_collapse_032919.dta"


set more off, perm
set matsize 1000

drop if inlist(statefip,2,15)

summ dBGTsupdemratebroad,d
replace dBGTsupdemratebroad=. if dBGTsupdemratebroad>r(p95) | dBGTsupdemratebroad<r(p5)


*Education

foreach unemp in du {

eststo clear

foreach var in neednoedu needhs needsc needbd needgd needbd_plus    {
	
	if "`var'"!="$educ"  {
	eststo, addscalars(ar3 e(r2_a)): reg d`var' `unemp' $weight $restric , cl(statefip)
		estadd local baseline "No", replace
		estadd local occyrfe "No", replace
		
	}
	
	if "`var'"=="$educ"  {	
		capture drop avgageexp
		gen avgageexp=bdshare2000
		capture drop initialneed
		gen initialneed=initial_`var'07
		
				eststo, addscalars(ar3 e(r2_a)):  areg d`var' `unemp'  $covars  $weight $restric  , cl(statefip) a(occyear)
				estadd local baseline "Yes", replace
				estadd local occyrfe "Yes", replace
			}
	}



}

*Experience

gen need0to2=need0to1 + need1to2
gen need2to4=need2to3 + need3to4
gen need4to7=need4to5 + need5to7
gen need4 = need3 + need3to4

foreach var of varlist need0to2  need2to4  need4 need4to7 {
gen d`var'=`var'-L3.`var' if year==2010
replace d`var'=`var'-L2.`var' if year==2012
}

gen initial_need407=initial_need4to507 + initial_need507



foreach unemp in du {

eststo clear

foreach var in needna need0to2  need2to4  need4to7 need7to15 need4    {
	
	
	if "`var'"!="$exper"  {
	eststo, addscalars(ar3 e(r2_a)): reg d`var' `unemp' $weight $restric , cl(statefip)
		estadd local baseline "No", replace
		estadd local occyrfe "No", replace
		
	}
	
	if "`var'"=="$exper"  {	
		capture drop avgageexp
		gen avgageexp=avgage2000
		capture drop initialneed
		gen initialneed=initial_`var'07
		
				eststo, addscalars(ar3 e(r2_a)):  areg d`var' `unemp'  $covars  $weight $restric  , cl(statefip) a(occyear)
				estadd local baseline "Yes", replace
				estadd local occyrfe "Yes", replace
			}
	}

}


********************************************************************************

foreach var in $educ $exper {

if "`var'"=="$educ" {
		capture drop avgageexp
		gen avgageexp=bdshare2000
		capture drop initialneed
		gen initialneed=initial_`var'07
		
	}

	if "`var'"=="$exper" {
		capture drop avgageexp
		gen avgageexp=avgage2000
		capture drop initialneed
		gen initialneed=initial_`var'07
		
	}

foreach unemp in dBGTsupdemratebroad  {
eststo clear

	eststo, addscalars(ar3 e(r2_a)): reghdfe d`var' `unemp'  $covars $weight $restric , a(occyear) vce(cluster statefip)
		estadd local occyrfe "Yes", replace
		estadd local statefe "No", replace
		estadd local occstfe "No", replace
		estadd local baseline "Yes", replace
		
	eststo, addscalars(ar3 e(r2_a)): reghdfe d`var' `unemp'  $covars $weight $restric , a(occyear statefip) vce(cluster statefip)
		estadd local occyrfe "Yes", replace
		estadd local statefe "Yes", replace
		estadd local occstfe "No", replace
		estadd local baseline "Yes", replace
		
		eststo, addscalars(ar3 e(r2_a)): reghdfe d`var' `unemp'  $covars $weight $restric , a(occyear panelid) vce(cluster statefip)
		estadd local occyrfe "Yes", replace
		estadd local statefe "No", replace
		estadd local occstfe "Yes", replace
		estadd local baseline "Yes", replace	


}
}




eststo, addscalars(ar3 e(r2_a)): reg dneedbd_plus du $weight $restric , cl(statefip)
estadd local baseline "No", replace
estadd local occyrfe "No", replace

eststo, addscalars(ar3 e(r2_a)): reg dneedbd_plus du year $weight $restric , cl(statefip)
estadd local baseline "No", replace
estadd local occyrfe "No", replace
		
	
capture drop avgageexp
gen avgageexp=bdshare2000
capture drop initialneed
gen initialneed=initial_needbd_plus07
		
eststo, addscalars(ar3 e(r2_a)):  areg dneedbd_plus du $covars  $weight $restric  , cl(statefip) a(occyear)
estadd local baseline "Yes", replace
estadd local occyrfe "Yes", replace


eststo, addscalars(ar3 e(r2_a)): reg dneed4 du $weight $restric , cl(statefip)
estadd local baseline "No", replace
estadd local occyrfe "No", replace

eststo, addscalars(ar3 e(r2_a)): reg dneed4 du year $weight $restric , cl(statefip)
estadd local baseline "No", replace
estadd local occyrfe "No", replace
		
capture drop avgageexp
gen avgageexp=avgage2000
capture drop initialneed
gen initialneed=initial_need407
		
eststo, addscalars(ar3 e(r2_a)):  areg dneed4 du  $covars  $weight $restric  , cl(statefip) a(occyear)
estadd local baseline "Yes", replace
estadd local occyrfe "Yes", replace



eststo, addscalars(ar3 e(r2_a)): reg dneedbd_plus du $weight $restric , cl(statefip)

eststo, addscalars(ar3 e(r2_a)): reg dneedbd_plus du year $weight $restric , cl(statefip)

eststo, addscalars(ar3 e(r2_a)):  areg dneedbd_plus du $weight $restric  , cl(statefip) a(year)

eststo, addscalars(ar3 e(r2_a)):  areg dneedbd_plus du  $weight $restric  , cl(statefip) a(occyear)

eststo, addscalars(ar3 e(r2_a)):  areg dneedbd_plus du  bdshare2000 initial_needbd_plus07  $weight $restric  , cl(statefip) a(occyear)

eststo, addscalars(ar3 e(r2_a)): reghdfe dneedbd_plus du bdshare2000 initial_needbd_plus07 $weight $restric , a(occyear statefip) vce(cluster statefip)

eststo, addscalars(ar3 e(r2_a)): reghdfe dneedbd_plus du bdshare2000 initial_needbd_plus07 $weight $restric , a(occyear panelid) vce(cluster statefip)




eststo, addscalars(ar3 e(r2_a)): reg dneedbd_plus dBGTsupdemratebroad $weight $restric , cl(statefip)

eststo, addscalars(ar3 e(r2_a)): reg dneedbd_plus dBGTsupdemratebroad year $weight $restric , cl(statefip)

eststo, addscalars(ar3 e(r2_a)):  areg dneedbd_plus dBGTsupdemratebroad $weight $restric  , cl(statefip) a(year)

eststo, addscalars(ar3 e(r2_a)):  areg dneedbd_plus dBGTsupdemratebroad  $weight $restric  , cl(statefip) a(occyear)

eststo, addscalars(ar3 e(r2_a)):  areg dneedbd_plus dBGTsupdemratebroad  bdshare2000 initial_needbd_plus07  $weight $restric  , cl(statefip) a(occyear)

eststo, addscalars(ar3 e(r2_a)): reghdfe dneedbd_plus dBGTsupdemratebroad bdshare2000 initial_needbd_plus07 $weight $restric , a(occyear statefip) vce(cluster statefip)

eststo, addscalars(ar3 e(r2_a)): reghdfe dneedbd_plus dBGTsupdemratebroad bdshare2000 initial_needbd_plus07 $weight $restric , a(occyear panelid) vce(cluster statefip)



eststo, addscalars(ar3 e(r2_a)): reg dneed4 du $weight $restric , cl(statefip)

eststo, addscalars(ar3 e(r2_a)): reg dneed4 du year $weight $restric , cl(statefip)

eststo, addscalars(ar3 e(r2_a)):  areg dneed4 du $weight $restric  , cl(statefip) a(year)

eststo, addscalars(ar3 e(r2_a)):  areg dneed4 du  $weight $restric  , cl(statefip) a(occyear)

eststo, addscalars(ar3 e(r2_a)):  areg dneed4 du  avgage2000 initial_need407  $weight $restric  , cl(statefip) a(occyear)

eststo, addscalars(ar3 e(r2_a)): reghdfe dneed4 du avgage2000 initial_need407 $weight $restric , a(occyear statefip) vce(cluster statefip)

eststo, addscalars(ar3 e(r2_a)): reghdfe dneed4 du avgage2000 initial_need407 $weight $restric , a(occyear panelid) vce(cluster statefip)



eststo, addscalars(ar3 e(r2_a)): reg dneed4 dBGTsupdemratebroad $weight $restric , cl(statefip)

eststo, addscalars(ar3 e(r2_a)): reg dneed4 dBGTsupdemratebroad year $weight $restric , cl(statefip)

eststo, addscalars(ar3 e(r2_a)):  areg dneed4 dBGTsupdemratebroad $weight $restric  , cl(statefip) a(year)

eststo, addscalars(ar3 e(r2_a)):  areg dneed4 dBGTsupdemratebroad  $weight $restric  , cl(statefip) a(occyear)

eststo, addscalars(ar3 e(r2_a)):  areg dneed4 dBGTsupdemratebroad  avgage2000 initial_need407  $weight $restric  , cl(statefip) a(occyear)

eststo, addscalars(ar3 e(r2_a)): reghdfe dneed4 dBGTsupdemratebroad avgage2000 initial_need407 $weight $restric , a(occyear statefip) vce(cluster statefip)

eststo, addscalars(ar3 e(r2_a)): reghdfe dneed4 dBGTsupdemratebroad avgage2000 initial_need407 $weight $restric , a(occyear panelid) vce(cluster statefip)




